#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：api_automation_test 
@File    ：hooks.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/7/21/021 16:33 
"""
import base64
import os
import time

import yaml


def get_current_highest():
    """获取当前时间戳"""
    return int(time.time())


def sum_data(a, b):
    """计算函数"""
    return a + b


def set_token(token: str):
    """设置token，直接返回字典"""
    return {"Authorization": token}


def promoter_submit_token(user_id, token):
    """
    需要生成申请人的token64
    :param user_id: 登录后返回的userid
    :param token: 登录后返回的token值
    :return: 返回加密后的密文
    """
    encrypt = "{}:{}".format(user_id, token)
    data = encrypt.encode("utf-8")
    token64 = "HBAPI " + "{}".format(base64.b64encode(data).decode("utf-8"))
    return token64


def read_promoter_user():
    """获取当前推广人的用户账号"""
    with open(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'config', 'config.yaml'), 'r',
              encoding='utf-8') as file:
        config_dict = yaml.load(
            file.read(), Loader=yaml.FullLoader)
    return config_dict.get("promoter_user").get("user_name")


